package com.survey.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.survey.common.annotation.Log;
import com.survey.common.core.controller.BaseController;
import com.survey.common.core.domain.AjaxResult;
import com.survey.common.enums.BusinessType;
import com.survey.system.domain.SurRegion;
import com.survey.system.service.ISurRegionService;
import com.survey.common.utils.poi.ExcelUtil;
import com.survey.common.core.page.TableDataInfo;

/**
 * 地区Controller
 * 
 * @author ruoyi
 * @date 2024-12-23
 */
@RestController
@RequestMapping("/system/region")
public class SurRegionController extends BaseController
{
    @Autowired
    private ISurRegionService surRegionService;

    /**
     * 查询地区列表
     */
    @PreAuthorize("@ss.hasPermi('system:region:list')")
    @GetMapping("/list")
    public AjaxResult list(SurRegion surRegion)
    {
        List<SurRegion> list = surRegionService.selectSurRegionList(surRegion);
        return success(list);
    }

    /**
     * 导出地区列表
     */
    @PreAuthorize("@ss.hasPermi('system:region:export')")
    @Log(title = "地区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SurRegion surRegion)
    {
        List<SurRegion> list = surRegionService.selectSurRegionList(surRegion);
        ExcelUtil<SurRegion> util = new ExcelUtil<SurRegion>(SurRegion.class);
        util.exportExcel(response, list, "地区数据");
    }

    /**
     * 获取地区详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:region:query')")
    @GetMapping(value = "/{regionId}")
    public AjaxResult getInfo(@PathVariable("regionId") Long regionId)
    {
        return success(surRegionService.selectSurRegionByRegionId(regionId));
    }

    /**
     * 新增地区
     */
    @PreAuthorize("@ss.hasPermi('system:region:add')")
    @Log(title = "地区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SurRegion surRegion)
    {
        surRegion.setCreateBy(getUsername());
        return toAjax(surRegionService.insertSurRegion(surRegion));
    }

    /**
     * 修改地区
     */
    @PreAuthorize("@ss.hasPermi('system:region:edit')")
    @Log(title = "地区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SurRegion surRegion)
    {
        surRegion.setUpdateBy(getUsername());
        return toAjax(surRegionService.updateSurRegion(surRegion));
    }

    /**
     * 删除地区
     */
    @PreAuthorize("@ss.hasPermi('system:region:remove')")
    @Log(title = "地区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{regionIds}")
    public AjaxResult remove(@PathVariable Long[] regionIds)
    {
        return toAjax(surRegionService.deleteSurRegionByRegionIds(regionIds));
    }

    /**
     * 获取地区树列表
     */
    @GetMapping("/treeList")
    public AjaxResult treeList(SurRegion surRegion)
    {
        return success(surRegionService.selectSurRegionTreeList(surRegion));
    }
}
